<template>
  <div>
    <Card>
      <div>
        <Button type="primary" ghost @click="addResource()">
          <Icon type="md-add"/>
          添加资源
        </Button>
      </div>

      <!--创建角色弹框-->
      <resource-add ref="resourceModal" :reloadData="reloadData"></resource-add>
<!--      <Button>添加</Button>-->
      <Input search enter-button placeholder="搜索..." />
    <Table :columns="columns" :data="menu_list" border>

      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" size="small" style="margin-right: 5px" @click="edit(row,index)">编辑</Button>
        <Button type="info" size="small" style="margin-right: 5px" @click="allotResourceRole(row,index)">分配资源</Button>
        <Button type="error" size="small" @click="deleteData(row,index)">删除</Button>
      </template>
    </Table>
    </Card>

  </div>
</template>
<script>
  import {getResourceList,deleteResource} from '@/api/base-manage/resource'
  import ResourceAdd from './resource-add'

  export default {
    components:{
      ResourceAdd
    },
    data () {
      return {
        columns: [
          {
            title: '菜单名称',
            key: 'name',
            tree: true
          },
          {
            title: '类型',
            key: 'type'
          },
          {
            title: '请求地址',
            key: 'url'
          },
          // {
          //   title: '组件路径',
          //   key: 'component_way'
          // },
          {
            title: '可见',
            key: 'isShow'
          },
          {
            title: '排序号',
            key: 'sortNum'
          },
          {
            title: '操作',
            key: 'action'
          }
        ],
        menu_list: [
          {
            id: '100',
            name: 'John Brown',
            age: 18,
            url: 'New York No. 1 Lake Park'
          },
          {
            id: '101',
            name: 'Jim Green',
            age: 24,
            url: 'London No. 1 Lake Park',
            children: [
              {
                id: '10100',
                name: 'John Brown',
                age: 18,
                url: 'New York No. 1 Lake Park'
              },
              {
                id: '10101',
                name: 'Joe Blackn',
                age: 30,
                url: 'Sydney No. 1 Lake Park'
              },
              {
                id: '10102',
                name: 'Jon Snow',
                age: 26,
                url: 'Ottawa No. 2 Lake Park',
                children: [
                  {
                    id: '1010200',
                    name: 'Jim Green',
                    age: 24,
                    url: 'New York No. 1 Lake Park'
                  }
                ]
              }
            ]
          },
          {
            id: '102',
            name: 'Joe Black',
            age: 30,
            url: 'Sydney No. 1 Lake Park'
          },
          {
            id: '103',
            name: 'Jon Snow',
            age: 26,
            url: 'Ottawa No. 2 Lake Park'
          }
        ]
      }
    },
    mounted() {
      this.reloadData()
    },
    methods:{
      allotResourceRole() {

      },
      addResource() {
          this.$refs.resourceModal.show();
          this.$refs.resourceModal.initData('')
      },
      reloadData() {
        getResourceList().then(res => {
          this.menu_list = res.data
        })
      },
    }

  }
</script>
